package com.informationsystem.service.impl;

import com.informationsystem.dao.EventDao;
import com.informationsystem.model.Event;
import com.informationsystem.service.EventManager;
import com.informationsystem.service.impl.GenericManagerImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.jws.WebService;

@Service("eventManager")
@WebService(serviceName = "EventService", endpointInterface = "com.informationsystem.service.EventManager")
public class EventManagerImpl extends GenericManagerImpl<Event, Long> implements EventManager {
    EventDao eventDao;

    @Autowired
    public EventManagerImpl(EventDao eventDao) {
        super(eventDao);
        this.eventDao = eventDao;
    }
    
	@Override
	public List getEventList() {
		List<Event> eventList = getAll();
		Collections.sort(eventList, new PostDateDsc());
		return eventList;
	}
	
	private  class PostDateDsc implements  Comparator<Event>{
		@Override
		public int compare(Event o1, Event o2) {
			return o2.getPostDate().compareTo(o1.getPostDate());
		}
	}

	@Override
	public List getTop3EventList() {
		List eventList = getEventList();
		if(eventList.size()>3)
		eventList = eventList.subList(0, 3);
		return eventList;
	}
}